#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	cin >> s;
	bool flag = 0;
	int ans1 = 0;
	int ans2 = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] >= 'A' && s[i] <= 'Z') {
			ans1++;
		}
		else {
			ans2++;
		}
	}
	if (ans1 == s.size())flag = 1;
	ans1 = 0, ans2 = 0;
	if (s[0] >= 'a' && s[0] <= 'z') {
		for (int i = 1; i < s.size(); i++) {
			if (s[i] >= 'A' && s[i] <= 'Z') {
				ans1++;
			}
			else {
				ans2++;
			}
		}
	}
	if (ans1 == s.size() - 1)flag = 1;
	if (!flag) {
		cout << s << endl;
	}
	else {
		for (int i = 0; i < s.size(); i++) {
			if (s[i] >= 'a' && s[i] <= 'z') {
				s[i] -= 32;
			}
			else {
				s[i] += 32;
			}
		}
		cout << s << endl;
	}
	return 0;
}